import request from "@/utils/request";

// 获取文章列表
export const getArticleAPI = async ({
  page = 1,
  limit = 10,
  keyword = "",
  categoryId = -1,
}) =>
  await request.get("/api/blog", {
    params: {
      page,
      limit,
      keyword,
      categoryId,
    },
  });

// 删除文章
export const deleteArticleAPI = async (id) =>
  await request.delete(`/api/blog/${id}`);

// 修改文章
export const updateArticleAPI = async (id, data) =>
  await request.put(`/api/blog/${id}`, data);

//查找文章
export const checkArticleAPI = async (id) =>
  await request.get(`/api/blog/${id}`);

//发布文章
export const publishArticleAPI = async (data) =>
  await request.post("/api/blog", data);

// 获取文章分类
export const getArticleCategoryAPI = async () =>
  await request.get("/api/blogtype");

// 添加文章分类
export const addArticleCategoryAPI = async ({ name, order }) =>
  await request.post("/api/blogtype", {
    name,
    order,
  });

// 修改文章分类
export const updateArticleCategoryAPI = async ({ id, name, order }) =>
  await request.put(`/api/blogtype/${id}`, {
    name,
    order,
  });

// 删除文章分类
export const deleteArticleCategoryAPI = async (id) =>
  await request.delete(`/api/blogtype/${id}`);
